#include <cocos2d.h>
#include <CCEGLView.h>
#include <SimpleAudioEngine.h>

#include "gofgame/jumpdown/AppDelegate.h"
#include "gofgame/common/Ref.h"
#include "gofgame/jumpdown/Scene.h"
#include "gofgame/jumpdown/MainScene.h"
#include "gofgame/jumpdown/util/objective-c.h"
#include "gofgame/jumpdown/Configuration.h"

using namespace CocosDenshion;
using namespace cocos2d;
using namespace gofgame::common;
using namespace gofgame::jumpdown;
using namespace gofgame::jumpdown::util;

AppDelegate::AppDelegate() {
}

AppDelegate::~AppDelegate() {
	SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching() {
    CCDirector *director = CCDirector::sharedDirector();
    director->setOpenGLView(CCEGLView::sharedOpenGLView());
    director->setDisplayStats(false);
	director->setAnimationInterval(1.0F / Configuration::getConfiguration().fps());

	/*Ref<Scene> scene;
	oc_new<Scene>(&scene);*/
	MainScene* ms = MainScene::createMainScene();
	director->runWithScene(ms);	
    return true;
}

void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
